package vip.xiaonuo.supplier.modular.warehouse.storesstream.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import vip.xiaonuo.common.annotation.CommonLog;
import vip.xiaonuo.common.pojo.CommonResult;
import vip.xiaonuo.supplier.modular.warehouse.stocks.param.SupplierStocksExportParam;
import vip.xiaonuo.supplier.modular.warehouse.storesstream.entity.SupplierStoresStream;
import vip.xiaonuo.supplier.modular.warehouse.storesstream.param.*;
import vip.xiaonuo.supplier.modular.warehouse.storesstream.service.SupplierStoresStreamService;

import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotEmpty;

import java.io.IOException;
import java.util.List;

/**
 * 库存流水控制器
 *
 * @author Mr.wu
 * @date  2025/03/19 09:49
 */
@Tag(name = "库存流水控制器")
@RestController
@Validated
public class SupplierStoresStreamController {

    @Resource
    private SupplierStoresStreamService supplierStoresStreamService;

    /**
     * 获取库存流水分页
     *
     * @author Mr.wu
     * @date  2025/03/19 09:49
     */
    @Operation(summary = "获取库存流水分页")
    @SaCheckPermission("/supplier/warehouse/storesstream/page")
    @GetMapping("/supplier/warehouse/storesstream/page")
    public CommonResult<Page<SupplierStoresStream>> page(SupplierStoresStreamPageParam supplierStoresStreamPageParam) {
        return CommonResult.data(supplierStoresStreamService.page(supplierStoresStreamPageParam));
    }

    /**
     * 添加库存流水
     *
     * @author Mr.wu
     * @date  2025/03/19 09:49
     */
    @Operation(summary = "添加库存流水")
    @CommonLog("添加库存流水")
    @SaCheckPermission("/supplier/warehouse/storesstream/add")
    @PostMapping("/supplier/warehouse/storesstream/add")
    public CommonResult<String> add(@RequestBody @Valid SupplierStoresStreamAddParam supplierStoresStreamAddParam) {
        supplierStoresStreamService.add(supplierStoresStreamAddParam);
        return CommonResult.ok();
    }

    /**
     * 编辑库存流水
     *
     * @author Mr.wu
     * @date  2025/03/19 09:49
     */
    @Operation(summary = "编辑库存流水")
    @CommonLog("编辑库存流水")
    @SaCheckPermission("/supplier/warehouse/storesstream/edit")
    @PostMapping("/supplier/warehouse/storesstream/edit")
    public CommonResult<String> edit(@RequestBody @Valid SupplierStoresStreamEditParam supplierStoresStreamEditParam) {
        supplierStoresStreamService.edit(supplierStoresStreamEditParam);
        return CommonResult.ok();
    }

    /**
     * 删除库存流水
     *
     * @author Mr.wu
     * @date  2025/03/19 09:49
     */
    @Operation(summary = "删除库存流水")
    @CommonLog("删除库存流水")
    @SaCheckPermission("/supplier/warehouse/storesstream/delete")
    @PostMapping("/supplier/warehouse/storesstream/delete")
    public CommonResult<String> delete(@RequestBody @Valid @NotEmpty(message = "集合不能为空")
                                                   List<SupplierStoresStreamIdParam> supplierStoresStreamIdParamList) {
        supplierStoresStreamService.delete(supplierStoresStreamIdParamList);
        return CommonResult.ok();
    }

    /**
     * 获取库存流水详情
     *
     * @author Mr.wu
     * @date  2025/03/19 09:49
     */
    @Operation(summary = "获取库存流水详情")
    @SaCheckPermission("/supplier/warehouse/storesstream/detail")
    @GetMapping("/supplier/warehouse/storesstream/detail")
    public CommonResult<SupplierStoresStream> detail(@Valid SupplierStoresStreamIdParam supplierStoresStreamIdParam) {
        return CommonResult.data(supplierStoresStreamService.detail(supplierStoresStreamIdParam));
    }

    /**
     * 库存流水导出
     *
     * @author Mr.wu
     * @date 2024/11/11 20:00
     */
    @Operation(summary = "库存流水导出")
    @CommonLog("库存导出")
    @SaCheckPermission("/supplier/warehouse/storesstream/export")
    @GetMapping(value = "/supplier/warehouse/storesstream/export", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
    public void exportStream(SupplierStoresStreamExportParam supplierStoresStreamExportParam, HttpServletResponse response) throws IOException {
        supplierStoresStreamService.exportStream(supplierStoresStreamExportParam, response);
    }
}
